package com.t309.tzy.service.impl;
import com.t309.tzy.entity.TSysUser;
import com.t309.tzy.mapper.TSysUserMapper;
import com.t309.tzy.service.ITsysUserService;
import com.t309.tzy.utils.PageSupport;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
@Transactional
@Service("tsysUserService")
public class TsysUserService implements ITsysUserService {

    public TsysUserService() {
        System.out.println("TsysUserService() : Spring容器给UserMapper对象依赖注入值");
    }

    @Resource
    private TSysUserMapper mapper;
    @Override
    public int login(String account, String password) {
        /*//使用静态工具类 创建SqlSession实例,返回Sql会话对象
        final SqlSession sqlSession = MyBatisUtil.createSqlSession();
        //调用Mapper层方法
        final int login = sqlSession.getMapper(TSysUserMapper.class).login(account, password);

        sqlSession.commit();
        MyBatisUtil.closeSqlSession(sqlSession);
        return login;*/
        return mapper.login(account,password);
    }

    @Override
    public List<TSysUser> getAllUsers() {
        return mapper.findAllUsers();
    }

    @Override
    public List<TSysUser> getAllUsersByPage(int currentNo, int pageSize) {
        return mapper.findAllUsersByPage(currentNo, pageSize);
    }

    @Override
    public TSysUser getUserInfoById(int id) {
        return mapper.findUserInfoById(id);
    }

    @Override
    public int getUserIdByAccount(String account) {
        return mapper.findUserIdByAccount(account);
    }

    @Override
    public Integer getUserCount(String realName,Integer roleId){
        return mapper.findUserCount(realName,roleId);
    }

    @Override
    public List<TSysUser> getUserListPagingByRealNameAndRoleId(String realName, Integer roleId, PageSupport pageSupport) {
        return mapper.findUserListPagingByRealNameAndRoleId(realName, roleId, pageSupport);
    }

    @Override
    public List<TSysUser> getUserListByRoleId(int roleId) {
        return null;
    }

    @Override
    public List<TSysUser> getUserListByRoleIdArray(Integer[] roleIds) {
        return null;
    }

    @Override
    public List<TSysUser> getUserListByRoleIdList(List<Integer> roleList) {
        return null;
    }

    public int insert(List<TSysUser> userList) {
        return 0;
    }

    public int insert(TSysUser user) {
        return mapper.insert(user);
    }

    @Override
    public int insertMultiple(List<TSysUser> userList) {
        return 0;
    }

    @Override
    public int update(TSysUser user) {
        return 0;
    }

    @Override
    public boolean updateUserPassword(int id, String newPassword) {
        return mapper.updateUserPassword(id, newPassword);
    }

    @Override
    public int delete(int id) {
        return mapper.delete(id);
    }


}
